# !/usr/bin/env python
# encoding: utf-8


"""
  @author: gaogao
  @file: scrolling.py
  @time: 2021/6/3 16:15
  @desc:
"""

import os
from pathlib import Path
import sys
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQuick import QQuickView

# This example uses a QML file to show a scrolling list containing
# all the items listed in dataList.

if __name__ == '__main__':
    dataList = ["Item 1", "Item 2", "Item 3", "Item 4"]

    app = QGuiApplication(sys.argv)
    view = QQuickView()

    ctxt = view.rootContext()
    ctxt.setContextProperty("myModel", dataList)

    qml_file = os.fspath(Path(__file__).resolve().parents[1] / 'usingmodel' / 'view.qml')
    print("qml", qml_file)
    view.setSource(QUrl.fromLocalFile(qml_file))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    app.exec()
    # Deleting the view before it goes out of scope is required to make sure all child QML instances
    # are destroyed in the correct order.
    del view
